#include <stdio.h>
#include <string.h>
#include "QHDX_main.h"

void DeleteStudentInfo()
{
	struct StudentInfo DelStudent, FindStudent;
	printf("\n欢迎使用删除模式\n");
	while(1)
	{
		printf("\n请输入您想删除学生的学号:>");
		if(1 != scanf("%d", &DelStudent.number))
		{
			printf("\n输入的学生学号%d有误，请重新输入！\n");
			while(getchar() != '\n');
			continue;
		}

		FILE* fp = fopen("StudentData","r+b");
		while(fread(&FindStudent, sizeof(FindStudent), 1, fp))
		{
			if(FindStudent.number == DelStudent.number)
			{
				fseek(fp, -sizeof(FindStudent), SEEK_CUR);
				memset(&FindStudent, 0, sizeof(FindStudent));
				fwrite(&FindStudent, sizeof(FindStudent), 1, fp);
				printf("成功删除学号为: %d 的学生", DelStudent.number);
				break;	
			}	
		}
		fclose(fp);
		printf("\n是否继续删除学生信息(y/n)\n");
		getchar();
		if(getchar() != 'y') break;
	}

}
